package com.itsm.service.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itsm.entity.File;
import com.itsm.entity.User;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 获取HR系统人员信息
 */
@Repository
@DS("slave")
public interface FileMapper extends BaseMapper<File> {

    //查询是在一级，二级，三级部门
    @Select("SELECT id,organization_level_1,organization_level_2,organization_level_3,name_chi,staff_num,position_name,duty_code FROM file WHERE staff_num = #{staff} and name_chi = #{name};")
    File getFile(String name,String staff);

    @Select("SELECT id,organization_level_1,organization_level_2,organization_level_3,name_chi,staff_num,position_name,duty_code FROM file WHERE organization_level_1 = #{org};")
    List<File> getEn(String org);

    @Select("SELECT id,organization_level_1,organization_level_2,organization_level_3,name_chi,staff_num,position_name,duty_code FROM file WHERE organization_level_2 = #{org};")
    List<File> getEn1(String org);


    //查询手机号，用于查询企微id
    @Select("SELECT mobile FROM file WHERE name_chi = #{name}")
    String getEnMobile(String name);

    //查询所有人员姓名，按工厂区分
    @Select("SELECT id,organization_level_1,organization_level_2,organization_level_3,name_chi,staff_num,position_name,duty_code FROM file WHERE whether_in_office = 1 and ((case when organization_level_1 like '江%' then 0 else 1 end) = #{plant} or (organization_level_1 not like '江%' and organization_level_1 not like '深%'))")
    List<File> getAllName(Integer plant);


    //查询所有人员姓名
    @Select("SELECT id,organization_level_1,organization_level_2,organization_level_3,name_chi,staff_num,position_name,duty_code FROM file WHERE whether_in_office = 1")
    List<File> getAllName1();



    //查询厂别
    @Select("SELECT case when organization_level_1 like '江%' then 0 else 1 end plant FROM file WHERE staff_num = #{staff} and whether_in_office =1 ")
    Integer getPlant(String staff);




}
